package com.nicefish.shiro;

import com.nicefish.shiro.realm.service.ServiceRealm;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ShiroHash {

    @Autowired
    HashedCredentialsMatcher matcher;

    @Autowired
    ServiceRealm serviceRealm;

    public String encrypt(String password, String username) {
        return new SimpleHash(matcher.getHashAlgorithmName(), password, serviceRealm.isUseSalt()?username:null, matcher.getHashIterations()).toHex();
    }

}
